<%@ page language="java"  pageEncoding="utf-8"%>
<%@ page import="packaging.*"%>
<%@ page import="java.sql.*"%>

<html>
	<head>
		
	</head>
	<body>
		<%  
		  String pp=(String)session.getAttribute("user");
         if(pp==null){
         response.sendRedirect("lp.jsp"); 
               }
		
			request.setCharacterEncoding("utf-8");
			check db = new check();
			String sql="select * from imp";
			ResultSet rs = db.indexs(sql);
				String page1 = (String) request.getParameter("page");
				if (page1 == null) {
					page1 = "0";
				}
				int pagesize = 6;//记录每页显示的条数
				rs.last();//定位最后那条记录
				int recordCount = rs.getRow();//取得最后一行号数
				int maxPage = 0;//看看有多少页
				maxPage = (recordCount % pagesize == 0) ? (recordCount / pagesize)
						: (recordCount / pagesize + 1);
				int currentPage = Integer.parseInt(page1);
				if (currentPage < 1) {
					currentPage = 1;
				} else {
					if (currentPage > maxPage) {
						currentPage = maxPage;
					}
				}
				rs.absolute((currentPage - 1) * pagesize + 1);
			
			%>
		
		<table border="1" align="center">

			<tr align="right">
				<td colspan="6">
							
				</td>
			</tr>
			<tr>
			  <th  width="126">
			产品
			  </th>
				<th  width="99">
					产品编号
				</th>
				
				<th  width="300">
					产品名称
				</th>
				<th width="99">
					产品原价
				</th>
				<th  width="99">
					产品特价
				</th>
				<th  width="120">
					操作
				</th>
			</tr>
			<%
					for (int i = 1; i <= pagesize; i++) {
			%>
			<tr >
			<td><img src="<%=rs.getString("p_imge")%>" width="120px" /></td>
			
				<td><%=rs.getObject("p_id")%></td>
				
				<td align="center"><a href="viewProduct.jsp?id=<%=rs.getObject("p_id")%>">
					<%=rs.getObject("p_name")%></a>
				</td>
				<td><%=rs.getObject("p_oldprice")%></td>
				<td><%=rs.getObject("p_newprice")%></td>
				<td align="center">
					
					<a href='editProduct.jsp?id=<%=rs.getObject("p_id")%>'>修改</a>|
					<a href='doDelProduct.jsp?id=<%=rs.getObject("p_id")%>' onclick="return del()">删除</a>
                    
				</td>
			</tr>
			<%
				if (!rs.next()) {
						break;
					}
				}
			%>
		</table>
		<p
				style="clear: both; margin-top: 0px; padding-top: 0px; padding-left: 400px">

				当前页数：<%=currentPage%>/<%=maxPage%>

				<%
					if (currentPage >= 1) {
				%>
				<a href="index.jsp?page=1">首页</a>
				<a href="index.jsp?page=<%=currentPage - 1%>"> 上一页</a>
				<%
					}
					if (currentPage <= maxPage) {
				%>
				<a href="index.jsp?page=<%=currentPage + 1%>"> 下一页</a>
				<a href="index.jsp?page=<%=maxPage%>"> 尾页</a>
				<%
					}
				%>
				
			</p>

	</body>

</html>






